package com.xiamaliu;

import com.xiamaliu.impl.JavaCourse;
import com.xiamaliu.impl.PythonCourse;

public class CourseFactory {

    public ICourse create(String type) {
        if ("java".equals(type)) {
            return new JavaCourse();
        } else if ("python".equals(type)) {
            return new PythonCourse();
        }
        return null;
    }

    public ICourse createOfClassName(String className) {
        try {
            if (className != null && !"".equals(className)) {
                return (ICourse) Class.forName(className).newInstance();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public ICourse createOfType(Class<? extends ICourse> type) {
        try {
            return type.newInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public <T> T createOfGenericsType(Class<T> type) {
        try {
            return type.newInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

}
